home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 272_01 / dup.doc < prev    next >
Text File  |  1987-03-26  |  1KB  |  46 lines

  1.  
  2.  
  3.         NAME
  4.                 dup -- duplicate a file handle
  5.  
  6.         SYNOPSIS
  7.                 nfh = dup(fh);
  8.                 int nfh;      new file handle
  9.                 int fh;       existing file handle
  10.  
  11.  
  12.         DESCRIPTION
  13.         This function uses the DOS "dup" function to create a duplicate
  14.         of an existing file handle.  The new file handle returned is
  15.         NULL if the dup process failed for any reason.  The use of
  16.         a duplicate file handle is primarily for causing an open
  17.         file to be "updated" to disk without closing and re-opening
  18.         it.  This is done by first flushing any buffered data out,
  19.         creating a duplicate file handle, and then closing the duplicate.
  20.         The original file handle is left unchanged, but the disk
  21.         directory and FAT are properly updated.
  22.  
  23.  
  24.  
  25.         EXAMPLE
  26.               (assume that fd is a previously opened FILE *fd)
  27.  
  28.               update_file() {
  29.                  int fh, nfh;
  30.                  fh = fileno(fd);      /* get the file handle */
  31.                  nfh = dup(fh);        /* get a duplicate handle */
  32.                  if(nfh == 0) return;  /* duplicate failed */
  33.                  fflush(fd);           /* insure all data written */
  34.                  close(nfh);           /* close duplicate handle */
  35.                  }
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.         This function is found in SMDLx.LIB for the Datalight Compiler.
  46.